<template>
  <div>
    <el-dialog title="管理跟进" :visible.sync="dialogVisible" width="30%"  @close="handleClose" >
      <el-form :model="formDate" :rules="rules" ref="ruleForm" size="mini" label-width="120px">
        <el-form-item label="跟进时间:" prop="trackingTime">
          <el-date-picker
            v-model="formDate.trackingTime"
            align="right"
            type="date"
            format="yyyy 年 MM 月 dd 日"
            value-format="yyyy-MM-dd"
            placeholder="选择日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="跟进方式:" prop="trackingMethod">
          <el-select  v-model="formDate.trackingMethod" placeholder="请选择" clearable>
            <el-option v-for="item in trackingMethodList" :key="item.cddValue"  :value="item.cddValue" :label="item.cddValue"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="跟进内容:" prop="trackingContent">
          <el-input v-model="formDate.trackingContent" :autosize="{ minRows: 2, maxRows: 6}" type="textarea" :rows="2"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="handleClose">取 消</el-button>
        <el-button type="primary" @click="btnOk">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import {getCustomerSetting} from "@/api/partner.js";
import { addManageTracking } from "@/api/fms.js";
const defaultForm = {
  customerId:'',
  trackingMethod: "", //跟进方式id
  trackingContent: "", //跟进内容
  trackingTime:'',
};
export default {
  name: "addManageFms",
  data() {
    return {
      dialogVisible: false,
      formDate: JSON.parse(JSON.stringify(defaultForm)),
      trackingMethodList: [],
      rules: {
        trackingTime: [
          { required: true, message: '请选择跟进时间', trigger: 'change' },
        ],
        trackingMethod: [
          { required: true, message: '请选择跟进方式', trigger: 'change' },
        ],
        trackingContent:[
          { required: true, message: '请输入跟进内容', trigger: 'blur' },
        ],

      }
    };
  },
  created() {

  },
  methods: {
    //跟进方式
    getCustomerSettingList(){
      getCustomerSetting().then((res)=>{
        res.forEach((el)=>{
         if(el.cdtCode == 'manage_tracking_method'){
            this.trackingMethodList = el.data;
          }
        });
      })
    },
    // 提交
    btnOk() {

      this.$refs.ruleForm.validate(async (valid) => {
        if (valid) {
          addManageTracking(this.formDate).then(()=>{
            this.$message({
              type: "success",
              message: "操作成功!",
            });
            this.handleClose();
            this.$emit('submit')
          })

        } else {
          return false;
        }
      })
    },
    // 回显
    async showDetail(item) {
      this.dialogVisible = true;
      this.formDate = JSON.parse(JSON.stringify(defaultForm))
      this.$nextTick(()=>{
        this.$refs.ruleForm.resetFields();
        this.formDate.customerId = item.customerId
        this.getCustomerSettingList()
      })

    },
    // 关闭弹框
    handleClose() {
      this.dialogVisible = false;
    },
  },
};
</script>

